/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sh.ndt.graph.mbean;

import com.sh.ndt.exam.entity.TestHistory;
import com.sh.ndt.user.mbean.RegisteredUsersDashboardBean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import org.apache.log4j.Logger;

import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;
import org.primefaces.model.chart.LineChartSeries;

/**
 *
 * @author Prashanth
 */
@ManagedBean(name = "chartBean")
@SessionScoped
public class ChartBean implements Serializable {

    private static final Logger LOGGER = Logger.getLogger(ChartBean.class);

//    @ManagedProperty(value = "#{registeredUsersDashboardBean}")
//    private RegisteredUsersDashboardBean registeredUsersDashboardBean;

    List<TestHistory> testHistoryList = new ArrayList<TestHistory>();

    private CartesianChartModel linearModel;
    private CartesianChartModel categoryModel;

    public ChartBean() {
        createLinearModel();
        createCategoryModel();
    }

    public CartesianChartModel getLinearModel() {
        createLinearModel();
        return linearModel;
    }

    private void createLinearModel() {
        linearModel = new CartesianChartModel();

        LineChartSeries series1 = new LineChartSeries();
        LineChartSeries series2 = new LineChartSeries();

//        series1.setLabel("Series 1");
//        series2.setLabel("Series 2");
//
//        for (int i = 1; i <= getTestHistoryList().size(); i++) {
//            series1.set(i, getTestHistoryList().get(i - 1).getPercentageSecured());
//            series1.set(i, getTestHistoryList().get(i - 1).getTestId());
//        }

        series1.set(1, 2);  
        series1.set(2, 1);  
        series1.set(3, 3);  
        series1.set(4, 6);  
        series1.set(5, 8);  
  
        series2.setLabel("Series 2");
        series2.setMarkerStyle("diamond");

        series2.set(1, 6);  
        series2.set(2, 3);  
        series2.set(3, 2);  
        series2.set(4, 7);  
        series2.set(5, 9);  
        linearModel.addSeries(series1);
        linearModel.addSeries(series2);
    }

    /**
     * @return the categoryModel
     */
    public CartesianChartModel getCategoryModel() {
        createCategoryModel();
        return categoryModel;
    }

    /**
     * @param categoryModel the categoryModel to set
     */
    public void setCategoryModel(CartesianChartModel categoryModel) {
        this.categoryModel = categoryModel;
    }

    private void createCategoryModel() {
        categoryModel = new CartesianChartModel();

        ChartSeries boys = new ChartSeries();
        boys.setLabel("Boys");

        boys.set("2004", 120);
        boys.set("2005", 100);
        boys.set("2006", 44);
        boys.set("2007", 150);
        boys.set("2008", 25);

        ChartSeries girls = new ChartSeries();
        girls.setLabel("Girls");

        girls.set("2004", 52);
        girls.set("2005", 60);
        girls.set("2006", 110);
        girls.set("2007", 135);
        girls.set("2008", 120);

        categoryModel.addSeries(boys);
        categoryModel.addSeries(girls);
    }

    /**
     * @return the testHistoryList
     */
    public List<TestHistory> getTestHistoryList() {
        //LOGGER.debug("Reg Bean: " + getRegisteredUsersDashboardBean());
        //this.testHistoryList = getRegisteredUsersDashboardBean().getTestHistoryList();
        return testHistoryList;
    }

    /**
     * @param testHistoryList the testHistoryList to set
     */
    public void setTestHistoryList(List<TestHistory> testHistoryList) {
        this.testHistoryList = testHistoryList;
    }

//    /**
//     * @return the registeredUsersDashboardBean
//     */
//    public RegisteredUsersDashboardBean getRegisteredUsersDashboardBean() {
//        return registeredUsersDashboardBean;
//    }
//
//    /**
//     * @param registeredUsersDashboardBean the registeredUsersDashboardBean to
//     * set
//     */
//    public void setRegisteredUsersDashboardBean(RegisteredUsersDashboardBean registeredUsersDashboardBean) {
//        this.registeredUsersDashboardBean = registeredUsersDashboardBean;
//    }
}
